package com.shop.item.atom.controller;

import com.shop.common.model.ServiceBean;
import com.shop.common.model.param.item.ItemBaseInput;
import com.shop.common.model.param.item.ItemDetailsInput;
import com.shop.common.model.result.item.ItemBaseOutput;
import com.shop.common.model.result.item.ItemDetailsOutput;
import com.shop.common.tmpl.BaseController;
import com.shop.item.api.service.ISolrService;
import com.shop.item.atom.ItemAtomApi;
import com.shop.item.atom.atomsvc.IItemAtomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AtomApiController extends BaseController implements ItemAtomApi {
    @Autowired
    IItemAtomService iItemAtomService;
    @Autowired
    ISolrService solrService;

    @Override
    public ItemBaseOutput qryItemBase(@PathVariable(value = "itemId") Integer itemId) {
        ItemBaseInput itemBaseInput = new ItemBaseInput();
        itemBaseInput.setItemId(itemId);
        return iItemAtomService.selectItemBase(itemBaseInput).getData();
    }

    @Override
    public List<ItemBaseOutput> qryItemBaseList(@RequestBody ItemBaseInput itemBaseInput) {
        ServiceBean<List<ItemBaseOutput>> serviceBean = iItemAtomService.selectItemBaseList(newParamMode(itemBaseInput));
        return serviceBean.getData();
    }

    @Override
    public ItemDetailsOutput qryItemDetails(@PathVariable(value = "itemId") Integer itemId) {
        ItemDetailsInput itemDetailsInput = new ItemDetailsInput();
        itemDetailsInput.setItemId(itemId);
        return iItemAtomService.selectItemDetails(itemDetailsInput).getData();
    }

    @Override
    public List<ItemDetailsOutput> qryItemDetailsList(@RequestBody ItemDetailsInput itemDetailsInput) {
        return iItemAtomService.qryItemDetailList(itemDetailsInput).getData();
    }

    @Override
    public String flushSolr() {
        return solrService.fullImport().getData();
    }
}
